function osl_startup( osldir )

global OSLDIR;

% osl_startup( osldir )
%
% SETS UP THE BASIC PATH SETTINGS
%
% MWW 2012

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% check path for other versions of:
checklist={'fieldtrip', 'spm', 'osl', 'mne', 'netlab', 'fsl', 'fmt'};

% and remove them:
oldpath=path;
indcolon=findstr(oldpath,':');   
st=1;
restoredefaultpath;

restoredpath=path;
addpath(genpath(osldir));
addpath(sprintf('%s/etc/matlab',getenv('FSLDIR')));

jj=1;
found=zeros(length(checklist),1);

for ii=1:length(indcolon),    
    pathlistitem=oldpath(st:indcolon(ii)-1);
    
    ok=1;
    for kk=1:length(checklist),        
        if(any(findstr(pathlistitem,checklist{kk}))),
           ok=0;            
           found(kk)=1;
        end;
    end;
    
    if(ok)
        if(~any(findstr(restoredpath,pathlistitem)))
            addpath(pathlistitem);
        end;
    end;
    
    st=indcolon(ii)+1;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%

OSLDIR=osldir;

spm_get_defaults('cmdline',true);
spm eeg;
close all;

for kk=1:length(checklist), 
    if found(kk),
        warning(['Found and removed paths that contain the string ' checklist{kk}]);
    end;
end;

